#ifndef _ARGCONFIG_H__
#define _ARGCONFIG_H__

#pragma once

#include "ConfigBase.h"

class CConfig
{
    CConfigBase m_cfgMgr;

    enum CONFIG_ID : uint8_t
    {
        WIFI_AP = 1,
        WIFI_PSW,
        BOILER_TURNON_DELAY,
        USER_KEY,
        TOPIC,
    };

    CConfig()
    {
    }

public:
    static CConfig &getSingleton()
    {
        static CConfig _singleton;
        return _singleton;
    }

    void Reset()
    {
        m_cfgMgr.Clear();
        m_cfgMgr.SaveConfig();
    }

    operator bool() const noexcept
    {
        return m_cfgMgr.IsValid();
    }

    String &GetTopic(String &out) const
    {
        out.clear();
        if (m_cfgMgr.IsValid())
        {
            m_cfgMgr.GetData((CConfigBase::DataIDType)TOPIC, out);
        }
        return out;
    }

    void SetTopic(const String &in)
    {
        m_cfgMgr.SetData((CConfigBase::DataIDType)TOPIC, in.c_str(), in.length());
    }

    String &GetKey(String &out) const
    {
        out.clear();
        if (m_cfgMgr.IsValid())
        {
            m_cfgMgr.GetData((CConfigBase::DataIDType)USER_KEY, out);
        }
        return out;
    }

    void SetKey(const String &in)
    {
        m_cfgMgr.SetData((CConfigBase::DataIDType)USER_KEY, in.c_str(), in.length());
    }

    String &GetWifiAP(String &out) const
    {
        out.clear();
        if (m_cfgMgr.IsValid())
        {
            m_cfgMgr.GetData((CConfigBase::DataIDType)WIFI_AP, out);
        }
        return out;
    }

    void SetWifiAP(const String &in)
    {
        m_cfgMgr.SetData((CConfigBase::DataIDType)WIFI_AP, in.c_str(), in.length());
    }

    String &GetWifiPsw(String &out) const
    {
        out.clear();
        if (m_cfgMgr.IsValid())
        {
            m_cfgMgr.GetData((CConfigBase::DataIDType)WIFI_PSW, out);
        }
        return out;
    }

    void SetWifiPsw(const String &in)
    {
        m_cfgMgr.SetData((CConfigBase::DataIDType)WIFI_PSW, in.c_str(), in.length());
    }

    uint32_t &GetDelay(uint32_t &out) const
    {
        out = 0;
        if (m_cfgMgr.IsValid())
        {
            out = m_cfgMgr.GetData<uint32_t>((CConfigBase::DataIDType)BOILER_TURNON_DELAY);
        }
        return out;
    }

    void setDelay(uint32_t in)
    {
        m_cfgMgr.SetData((CConfigBase::DataIDType)BOILER_TURNON_DELAY, in);
    }

    void SaveConfig()
    {
        m_cfgMgr.SaveConfig();
    }
};
#endif